// components/common/CommodityItem/CommodityItem.js
import { API_HOST, RES_HOST } from "../../../utils/const";
import http from "../../../utils/http";
import util from "../../../utils/util";
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    propertyItem: {
      type: Object,
      value: {
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    host: API_HOST,
    res_host: RES_HOST,
    publishTime: '',
    defaultMaxPrice: '',
    defaultMinPrice: ''
  },

  attached: function () {
    this.formatDate(this.properties.propertyItem);
  },

  /**
   * 组件的方法列表
   */
  methods: {
    goDetail: function(){
      console.log('goDetail', this.data.propertyItem.id);
      wx.navigateTo({
        url: '/pages/index/propertyDetailA/propertyDetailA?preId=' + this.data.propertyItem.id + '&isShared=no'
      })
    },
    formatDate: function(data){
      //console.log('====formatDate:', util.getMonthDay(data.publishTime));
      let time = util.getMonthDay(data.publishTime);
      let unit = data.priceUnit,
        defaultMaxPrice, defaultMinPrice;
      if (unit === '元/月') {
        defaultMaxPrice = (data.monthGuidePriceHigh).toFixed(0);
        defaultMinPrice = (data.monthGuidePriceLow).toFixed(0);
        console.log('元/月defaultMaxPrice:', defaultMaxPrice, 'defaultMinPrice:', defaultMinPrice);
      } else if (unit === '万元/年') {
        defaultMaxPrice = (data.yearGuidePriceHigh).toFixed(0);
        defaultMinPrice = (data.yearGuidePriceLow).toFixed(0);
        console.log('万元/年defaultMaxPrice:', defaultMaxPrice, 'defaultMinPrice:', defaultMinPrice);
      } else if (unit === '元/㎡/日') {
        defaultMaxPrice = (data.dayGuidePriceHigh).toFixed(1);
        defaultMinPrice = (data.dayGuidePriceLow).toFixed(1);
        console.log('元/㎡/日defaultMaxPrice:', defaultMaxPrice, 'defaultMinPrice:', defaultMinPrice);
      }
      this.setData({
        publishTime: time,
        defaultMaxPrice: defaultMaxPrice,
        defaultMinPrice: defaultMinPrice
      })
    }
  }
})
